<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('报修时间')">
              <a-date-picker :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择开始时间')"
                class="query-group-cust" v-model="queryParam.createTime_begin"></a-date-picker>
              <span class="query-group-split-cust"></span>
              <a-date-picker :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择结束时间')"
                class="query-group-cust" v-model="queryParam.createTime_end"></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('竣工时间')">
              <a-date-picker :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择开始时间')"
                class="query-group-cust" v-model="queryParam.completeTime_begin"></a-date-picker>
              <span class="query-group-split-cust"></span>
              <a-date-picker :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss" dateFormat="YYYY-MM-DD HH:mm:ss" :placeholder="$t('请选择结束时间')"
                class="query-group-cust" v-model="queryParam.completeTime_end"></a-date-picker>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('机台名称')">
              <j-search-select-tag :placeholder="$t('请选择机台名称')" v-model="queryParam.gameId" dict="bis_game,name,id" />
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="7" :sm="24">
            <a-form-item :label="$t('工单状态')">
              <j-search-select-tag :placeholder="$t('请选择工单状态')" v-model="queryParam.taskStatus"
                dict="bis_game_repair.task_status" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('报修人')">
                <a-select v-model="queryParam.createBy" :placeholder="$t('请选择报修人')">
                  <a-select-option v-for="(item, index) in userList" :value="item.id" :key="index">{{
                    item.realname
                    }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('维修员')">
                <a-select v-model="queryParam.repairBy" :placeholder="$t('请选择维修员')">
                  <a-select-option v-for="(item, index) in userList" :value="item.id" :key="index">{{
                    item.realname
                    }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                $t('重置')
                }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'BisGameRepair:add'">{{ $t('新增') }}</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('机台维修')" v-has="'BisGameRepair:export'">{{
        $t('导出')
        }}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <div v-else>
            <a-popover v-for="(item, index) in text" :key="index" trigger="hover">
              <template slot="content">
                <img :src="getImgView(item.path)" style="max-width: 400px; max-height: 400px;" />
              </template>
              <img :src="getImgView(item.path)" height="25px" alt=""
                style="max-width:80px;font-size: 12px;font-style: italic;margin-right: 5px;" />
            </a-popover>
          </div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record, 1)" v-has="'BisGameRepair:repair'" v-if="record.taskStatus != 2">{{ $t('维修')
            }}</a>
          <a-divider type="vertical" v-has="'BisGameRepair:repair'" v-if="record.taskStatus != 2" />
          <a @click="handleEdit(record, 0)" v-has="'BisGameRepair:edit'" v-if="record.taskStatus != 2">{{ $t('编辑')
            }}</a>
          <a-divider type="vertical" v-has="'BisGameRepair:edit'" v-if="record.taskStatus != 2" />
          <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
            <a v-has="'BisGameRepair:delete'">{{ $t('删除') }}</a>
          </a-popconfirm>
          <a-divider type="vertical" v-has="'BisGameRepair:delete'" />
          <a @click="handleDetail(record)">{{ $t('详情') }}</a>
        </span>
      </a-table>
    </div>

    <bis-game-repair-modal ref="modalForm" @ok="modalFormOk"></bis-game-repair-modal>
  </a-card>
</template>

<script>

import { getAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import BisGameRepairModal from './modules/BisGameRepairModal'
import moment from 'moment'

export default {
  name: 'BisGameRepairList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BisGameRepairModal
  },
  data() {
    return {
      description: '机台维修管理页面',
      moment,
      // 表头
      columns: [
        {
          title: this.$t('报修时间'),
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: this.$t('报修人'),
          align: "center",
          dataIndex: 'createBy'
        },
        {
          title: this.$t('机台名称'),
          align: "center",
          dataIndex: 'gameId_dictText'
        },
        {
          title: this.$t('工单状态'),
          align: "center",
          dataIndex: 'taskStatus_dictText'
        },
        {
          title: this.$t('问题描述'),
          align: "center",
          dataIndex: 'description'
        },
        {
          title: this.$t('故障图片'),
          align: "center",
          dataIndex: 'imageList',
          scopedSlots: { customRender: 'imgSlot' },
        },
        {
          title: this.$t('竣工时间'),
          align: "center",
          dataIndex: 'completeTime'
        },
        {
          title: this.$t('维修员'),
          align: "center",
          dataIndex: 'repairBy'
        },
        {
          title: this.$t('维修信息'),
          align: "center",
          dataIndex: 'repairInfo'
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/game/bisGameRepair/list",
        delete: "/game/bisGameRepair/delete",
        exportXlsUrl: "/game/bisGameRepair/exportXls",
      },
      dictOptions: {},
      superFieldList: [],
      userList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
      getAction('/sys/user/list').then((res) => {
        if (res.success) {
          this.userList = res.result.records
          this.userList.forEach((col) => {
            col.id = col.realname
          })
          this.userList.unshift({ id: '', realname: this.$t('全部') })
        }
      })
    },
    handleEdit(record, type) {
      this.$refs.modalForm.edit(record, type)
      if (type == 0) {
        this.$refs.modalForm.title = this.$t('编辑')
      } else {
        this.$refs.modalForm.title = this.$t('维修')
      }
      this.$refs.modalForm.disableSubmit = false;
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'createBy', text: '报修人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '保修时间' })
      fieldList.push({ type: 'int', value: 'tenantId', text: '租户', dictCode: '' })
      fieldList.push({ type: 'string', value: 'gameId', text: '机台id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'taskStatus', text: '工单状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'description', text: '问题描述', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'completeTime', text: '竣工时间' })
      fieldList.push({ type: 'string', value: 'repairBy', text: '维修员', dictCode: '' })
      fieldList.push({ type: 'string', value: 'repairInfo', text: '维修信息', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>